import {
  fmoney,
  fnum
} from '../utils/fmoney';

export default {
  install(Vue, options = {}) {
    Vue.directive('fmoney', {
      inserted: (el, binding) => {
        el.innerHTML = `<i>￥</i>${fmoney(binding.value)}`;
      },
      update: (el, binding) => {
        el.innerHTML = `<i>￥</i>${fmoney(binding.value)}`;
      }
    });
    Vue.directive('fnum', {
      inserted: (el, binding) => {
        el.innerHTML = `${fnum(binding.value)}`;
      },
      update: (el, binding) => {
        el.innerHTML = `${fnum(binding.value)}`;
      }
    });
    Vue.directive('ftitle', {
      inserted: el => {
        const list = el.innerText.split('');
        let title = '';
        list.forEach(val => {
          title = `${title}<p>${val}</p>`;
        });
        el.innerHTML = title;
      }
    });
  }
};
